<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="DataTables/datatables.min.css"/>
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>车辆管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
	<span class="c-gray en">&gt;</span>
	系统管理
	<span class="c-gray en">&gt;</span>
	车辆管理
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container" id="app">
	<div class="text-c">
		<form id="queryForm">
			<span class="select-box inline" v-if="isAdmin">
				<select class="select" id="companyid" name="line.team.company.companyid"></select>
			</span>
			<input type="text" name="line.lineid" id="query" placeholder="请输入线路号" style="width:250px" class="input-text" v-model="msg">
			<button class="btn btn-success" type="button" v-on:click="query()"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
		</form>
	</div>
	<div class="mt-20">
		<table id="list" class="table table-border table-bordered table-hover table-bg table-sort">
		</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="DataTables/datatables.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/vue.js" charset="utf-8"></script>
<script type="text/javascript">
/*系统-车队-添加*/
function system_category_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*系统-车队-编辑*/
function system_category_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*系统-车队-删除*/
function system_category_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			beforeSend: function (request) {
				request.setRequestHeader("Authorization", "Bearer " + getToken());
			},
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
	});
}
</script>

<script type="text/javascript">
	$(function(){
		$.ajax({
			// url: '/apis/base/company/getList',
			url: 'http://localhost:8080/base/company/getList',
			data: {
				order: "ordercode"
			},
			beforeSend: function (request) {
				request.setRequestHeader("Authorization", "Bearer " + getToken());
			},
			method:'GET',
			success:function (data,status,request) {
				console.log(data);
				$("#companyid").append("<option value>请选择分公司</option>");
				for(var i = 0; i < data.length; i ++){
					$("#companyid").append("<option value='" + data[i].companyid + "'>" + data[i].companyname + "</option>");
				}
			},
			error:function (request, msg, obj) {
				var respTxtObj = JSON.parse(request.responseText);
				console.log(respTxtObj);
				console.log(respTxtObj.error);
				console.log(respTxtObj.error_description);
			}
		});
	});
	
	var vm = new Vue({
		el : "#app",
		data : {
			msg : "",
			isAdmin : true
		},
		//在实例初始化之后，数据观测 (data observer) 和 event/watcher 事件配置之前被调用。
		beforeCreate:function(){
			console.log('beforeCreate');
		},
		/* 在实例创建完成后被立即调用。
		在这一步，实例已完成以下的配置：数据观测 (data observer)，属性和方法的运算，watch/event 事件回调。
		然而，挂载阶段还没开始，$el 属性目前不可见。 */
		created	:function(){
			console.log('created');
		},
		//在挂载开始之前被调用：相关的渲染函数首次被调用
		beforeMount : function(){
			console.log('beforeMount');
	
		},
		//el 被新创建的 vm.$el 替换, 挂在成功	
		mounted : function(){
			console.log('mounted');
		
		},
		//数据更新时调用
		beforeUpdate : function(){
			console.log('beforeUpdate');
				
		},
		//组件 DOM 已经更新, 组件更新完毕 
		updated : function(){
			console.log('updated');
				
		},
		methods: {
			query: function(){
				table.draw();
			}
		}
	});
	
	var table = $('#list').DataTable({
		language: {
			"processing": "处理中...",
			"lengthMenu": "显示 _MENU_ 项结果",
			"zeroRecords": "没有匹配结果",
			"info": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
			"infoEmpty": "显示第 0 至 0 项结果，共 0 项",
			"infoFiltered": "(由 _MAX_ 项结果过滤)",
			"infoPostFix": "",
			"search": "搜索:",
			"url": "",
			"emptyTable": "表中数据为空",
			"loadingRecords": "载入中...",
			"infoThousands": ",",
			"paginate": {
				"first": "首页",
				"previous": "上页",
				"next": "下页",
				"last": "末页"
			},
			"aria": {
				"sSortAscending": ": 以升序排列此列",
				"sSortDescending": ": 以降序排列此列"
			}
		},
		stateSave: true,
		searching: false,
		processing: true,
		serverSide: true,
		order: [[1, 'asc']],
		ajax: {
			// url: '/apis/base/vehicle/getTablePage',
			url: 'http://localhost:8000/vehicle/getTablePage',
			type: 'GET',
			data: function ( data ) {
				var param = {};
				var userInfo = getUserInfo();
				var page = data.start == 0 ? 0 : data.start / data.length;
				var size = data.length;
				var order = data.columns[data.order[0].column].data + " " + data.order[0].dir;
				param.draw = data.draw;
				param.page = page;
				param.size = size;
				param.like = '%line.lineid%';
				param.order = order;
				var formData = $("#queryForm").serializeArray();//把form里面的数据序列化成数组
				formData.forEach(function (e) {
					param[e.name] = e.value;
				});
				
				// if($('#companyid').val() != null && $('#companyid').val() != ""){
				// 	param['line.team.company.companyid'] = $('#companyid').val();
				// }
				// param['line.lineid'] = vm.msg;
				if(hasRole('COMPANY')){
					vm.isAdmin = false;
					// param['line.team.company.companyid'] = userInfo.company.companyid;
				}
				return param;
			}
		},
		columns: [
			{title: '<input type="checkbox"/>',
				render: function(data, type, row, meta) {
					return "<input type='checkbox' name='ids' value='" + row.vehicleid +"'/>";
				}
			},
			{title: '分公司', name: 'companyname', data: 'line.team.company.companyname', defaultContent: '无'},
			{title: '车队', name: 'teamname', data: 'line.team.teamname', defaultContent: '无',
				render: function(data, type, row, meta) {
					return row.line.team.teamname + '(' + row.line.team.teamid + ')';
				}
			},
			{title: '线路', name: 'lineid', data: 'line.lineid', defaultContent: '无',
				render: function(data, type, row, meta) {
					return row.line.linename + '(' + row.line.lineid + ')';
				}
			},
			{title: '车辆号', name: 'vehicleid', data: 'vehicleid', defaultContent: ''},
			{title: '车牌', name: 'vehicleno', data: 'vehicleno', defaultContent: ''},
			{title: '状态', name: 'status', data: 'status', defaultContent: '',
				render: function(data, type, row, meta) {
					return row.status == 'Y' ? '启用' : '停用';
				}
			}
		],
		columnDefs: [
			// {
			// 	'targets': 0,
			// 	'searchable': false,
			// 	'orderable': false,
			// 	'className': 'dt-body-center',
			// 	'render': function (data, type, full, meta){
			// 		return '<input type="checkbox" name="id[]" value="' + $('<div/>').text(data).html() + '">';
			// 	 }
			// },
			{"orderable":false,"targets":[0,6]}
		]
	});
</script>
</body>
</html>